#include "XTextureD3D9.h"

XTextureD3D9::XTextureD3D9(){
	m_texture = NULL;
}
XTextureD3D9::~XTextureD3D9(){
	if (m_texture != NULL)
		m_texture->Release();
}

bool XTextureD3D9::LoadResource(XModFileStream file_stream){
	if (file_stream.IsLoaded()){
		HRESULT hr = D3DXCreateTextureFromFileInMemory((LPDIRECT3DDEVICE9)XRender::GetInstance()->GetDevice(), file_stream.GetData(), file_stream.Size(), &m_texture);
		if (m_texture == NULL)
			return false;
		D3DSURFACE_DESC d3d_desc;
		m_texture->GetLevelDesc(0, &d3d_desc);
		m_Height = d3d_desc.Height;
		m_Width = d3d_desc.Width;
		m_format = d3d_desc.Format;
		m_Miplevels = m_texture->GetLevelCount();
		m_pool = d3d_desc.Pool;
		m_usage = d3d_desc.Usage;
		return true;
	}
	return false;
}

LPDIRECT3DTEXTURE9 XTextureD3D9::GetTextureD3D(){
	return m_texture;
}